import { ModalForm, ProFormSelect } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { PropsWithChildren } from 'react';

interface UpdateFormProps {
  classCategoryEnum: Map<number, { text: string }>;
  children: any;
  echoRecord: API.StudentInfo;
}
const AssignForm: React.FC<PropsWithChildren<UpdateFormProps>> = ({
  children,
  echoRecord,
}) => {
  const { assignHandler, classCategoryEnum } = useModel(
    'Student.model',
    (model) => ({
      assignHandler: model.assignHandler,
      classCategoryEnum: model.classCategoryEnum,
    }),
  );

  return (
    <ModalForm<API.Student_Assign_Body>
      trigger={children}
      title="选择班级"
      autoFocusFirstInput
      initialValues={echoRecord}
      submitTimeout={2000}
      modalProps={{ destroyOnClose: true }}
      onFinish={async (values) => {
        const success = await assignHandler({
          ...values,
          stu_id: echoRecord.stu_id,
        });
        return success;
      }}
    >
      <ProFormSelect
        name="stu_cls_id"
        label="班级名称"
        placeholder="请选择班级"
        valueEnum={classCategoryEnum}
        rules={[{ required: true, message: '班级为必选项' }]}
      />
      {/* <ProFormSelect
        name='stu_cls_id'
        label='班级名称'
        valueEnum={classCategoryEnum}  
      /> */}
    </ModalForm>
  );
};

export default AssignForm;
